package com.bigknow.appstore.web.console.service.impl;

import com.bigknow.appstore.web.console.app.Application;
import com.bigknow.appstore.web.console.app.ApplicationCategory;
import com.bigknow.appstore.web.console.dao.IApplicationCategoryDao;
import com.bigknow.appstore.web.console.service.IApplicationCategoryService;
import com.bigknow.appstore.web.framework.service.BaseCRUDService;
import org.apache.commons.lang3.StringUtils;
import org.mongodb.morphia.Datastore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 李科风 on 2016-09-27.
 */
@Service
public class ApplicationCategoryService extends BaseCRUDService<ApplicationCategory, IApplicationCategoryDao> implements IApplicationCategoryService {

    @Autowired
    private Datastore ds;

    public ApplicationCategory getCategory(String id) {
        if (!StringUtils.isEmpty(id)) {
            return ds.find(ApplicationCategory.class).filter("id", id).get();
        }
        return null;
    }

    @Override
    public int getAppCount(ApplicationCategory category) {
        return (int) ds.find(Application.class, "categoryId", category.getId()).countAll();
    }
}
